
const utils = require('../../../../common/util/util')
Page({
    data: {
        writed : '' ,
        show: false,
        type:-1,
        xUserInfo:{},
        num:'',
        id:'',
        sub_classification_number:'',
        rept:[],
        name:'',
        dayremb:[]
    },
    onLoad: function (options) {
      let that =this;
      // this.setData({
      //    type:options.type,
      //    writed:JSON.parse(options.datas)
      //  })
      //  console.log(this.data.writed)
      that.setData({
        num:options.num,
        id:options.id,
        sub_classification_number:options.sub_classification_number,
        name:options.name
      })
      if(that.data.num==2){
          // 日记
        that.xGetdayremb(that.data.id,that.data.sub_classification_number)
      }else if(that.data.num==6){
          // 疼痛日记
          that.xGetpain(that.data.id)
      }else if(that.data.num==5 || that.data.num==4){
        // 循环练习
          that.xGetAction(that.data.id)
      }else if(that.data.num==10){
        // 压力源
        that.xGetpressuresource(that.data.id)
      }else if(that.data.num==11){
        //沟通技巧练习
        that.xGetcommunication_skills(that.data.id)
      }

      wx.setNavigationBarTitle({
        title: that.data.name,
      })
    },
    onShow:function(){
      let that =this;
    },
    // 日记
    xGetdayremb:function(id,number){
      let that = this
      let _dataObj = {
        _openid: id, //用户对openid
        sub_classification_number:number //对应日记中的writing_class_number
      }
      wx.cloud.callFunction({
        name: 'consultant_workbench',
        data: {
          action: "get_job_record_by_class",
          dataObj: _dataObj
        }
      }).then(res => {
        let data =res.result
        for(let index in data){
          data[index].create_time=utils.formatTime_emotion(new Date(data[index].create_time))
        }
        that.setData({
          dayremb:data
        })
        console.log(that.data.dayremb)
      })
    },
    // 疼痛日记
    xGetpain:function(id){
        let that =this
        wx.cloud.callFunction({
          name: 'consultant_workbench',
          data: {
            action: "get_all_pain_diary",
            user_openid: id // 制定用户的openid
          }
        }).then(res => {
          let data =res.result
            for(let index in data){
              data[index].create_time=utils.formatTime_emotion(new Date(data[index].create_time))
            }
            that.setData({
              dayremb:data
            })
        })
    },
    // 循环练习
    xGetAction:function(id){
        let that =this
        wx.cloud.callFunction({
          name: 'consultant_workbench',
          data: {
            action: "get_practice_feeling",
            user_openid: id // 制定用户的openid
          }
        }).then(res => {
          let data =res.result
          for(let index in data){
            data[index].create_time=utils.formatTime_emotion(new Date(data[index].create_time))
          }
          that.setData({
            dayremb:data
          })
        })
    },
     // 压力源
     xGetpressuresource:function(id){
      let that =this
      wx.cloud.callFunction({
        name: 'consultant_workbench',
        data: {
          action: "get_all_pressure_source",
          user_openid: id // 制定用户的openid
        }
      }).then(res => {
        let data =res.result
        for(let index in data){
          data[index].create_time=utils.formatTime_emotion(new Date(data[index].create_time))
        }
        that.setData({
          dayremb:data
        })
      })
    },
    // 沟通技巧练习
    xGetcommunication_skills:function(id){
      let that =this
      wx.cloud.callFunction({
        name: 'consultant_workbench',
        data: {
          action: "get_communication_skills",
          user_openid: id // 指定用户的openid
        }
      }).then(res => {
        let data =res.result
        for(let index in data){
          data[index].create_time=utils.formatTime_emotion(new Date(data[index].create_time))
        }
        that.setData({
          dayremb:data
        })
      })
    },
    // getUser:function(){
    //   let that =this;
    //   wx.cloud.callFunction({
    //     name: 'user',
    //     data: {
    //         action: 'detail'
    //     }
    // }).then(res => {
    //     let user = res.result
    //     that.setData({
    //         xUserInfo: user
    //     })
    // })
    // }
})